{% extends "base.html" %}
{% import "bootstrap/wtf.html" as wtf %}
{% import "_macros.html" as macros %}
{% import "demand/partial/search_renewable_demand_form.html" as search_demand_form_macro %}
{% import "demand/partial/renewable_demand_table.html" as demand_table_macro %}

{% block title %}万屏时代OPC--{{ page_title }}{% endblock %}

{% block panel_heading %}
    万屏时代OPC--{{ page_title }}
{% endblock %}

{% block panel_body %}
    {% if has_search %}
        {{ search_demand_form_macro.gen_form(form, form_route, current_user) }}
    {% endif %}

    {% if pagination %}
        <div class="pagination">
            {{ macros.pagination_widget(pagination, url, **url_kwargs) }}
        </div>
    {% endif %}

    {{ demand_table_macro.gen_table(demands, url) }}

    {% if pagination %}
        <div class="pagination">
            {{ macros.pagination_widget(pagination, url, **url_kwargs) }}
        </div>
    {% endif %}

    <div class="modal fade" id="remark_modal" role="dialog">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"
                            aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">客户: <span
                            id="remark_modal_client_name"></span>(备注信息)</h4>
                </div>
                <div class="modal-body">
                    <form action="" class="form form-inline">
                        <div class="form-group">
                            <div class="row">
                                <label class="control-label  col-xs-3 col-xs-offset-1"
                                       for="reason">管理员备注:</label>
                                <div class="col-xs-8">
                                    <textarea id="remark_modal_admin_remark"
                                              rows="10" cols="50"
                                              readonly></textarea>
                                </div>
                            </div>
                            <div class="row">
                                <label class="control-label  col-xs-3 col-xs-offset-1"
                                       for="reason">客户备注:</label>
                                <div class="col-xs-8">
                                    <textarea id="remark_modal_remark" rows="5"
                                              cols="50" readonly></textarea>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block scripts %}
    {{ super() }}
    <script>
        $(document).ready(function () {
            setTimeout(function () {
                window.location.reload()
            }, 5 * 60 * 1000)
        })

    </script>

    <script>
        $(document).ready(function () {
            // 作废操作
            $('#demand-info-table .for-renewable-operate-btn').each(function (i, obj) {
                $(obj).click(function () {
                    if (confirm('确定要作废吗?')) {
                        var record_id = $(this).data('record_id');
                        var operated_status = $(this).data('operated_status');
                        $.ajax({
                            url: "{{ url_for('op_bp.ajax_demand_operator')}}",
                            data: JSON.stringify({
                                'record_id': record_id,
                                'operated_status': operated_status
                            }),
                            type: 'post',
                            dataType: 'json',
                            contentType: 'application/json',
                            cache: true
                        }).done(function (data) {
                            if (data.status) {
                                window.location.reload()
                            }
                            else {
                                $(obj).data('content', '当前操作失败了，订单可能已经被处理过了');
                                $(obj).popover('show');
                            }

                        }).fail(function () {
                            $(obj).data('content', '服务器错误');
                            $(obj).popover('show');
                        });
                    }
                });
            });
            $('#export-renewable_demand_list').click(function () {
                var url = '{{ url_for('op_bp.export_renewable_demand_list') }}';
                url = url + '?' +
                    'id=' + $('#id').val() +
                    '&uid=' + $('#uid').val() +
                    '&user_phone=' + $('#user_phone').val() +
                    '&prov=' + $('#prov').val() +
                    '&cate=' + $('#cate').val() +
                    '&malf=' + $('#malf').val() +
                    '&type=' + $('#type').val() +
                    '&surr=' + $('#surr').val() +
                    '&color=' + $('#color').val() +
                    '&status=' + $('#status').val() +
                    '&tag=' + $('#tag').val() +
                    '&source=' + $('#source').val() +
                    '&admin_remark=' + $('#admin_remark').val() +
                    '&remark=' + $('#remark').val() +
                    '&admin_id=' + $('#admin_id').val() +
                    '&operated_status=' + $('#operated_status').val() +
                    '&created_at_begin=' + $('#created_at_begin').val() +
                    '&created_at_end=' + $('#created_at_end').val() +
                    '&published_at_begin=' + $('#published_at_begin').val() +
                    '&published_at_end=' + $('#published_at_end').val();

                if ($('#has_audio').is(':checked')) {
                    url = url + 'has_audio=1'
                }
                window.location.href = url;
            });

        })
    </script>
{% endblock %}

